//
//  UIBarButtonItem+Extension.swift
//  SinaWeiBo
//
//  Created by 毛强 on 16/1/12.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(imageName:String? = nil, title:NSString? = nil, target:AnyObject?, action:Selector) {
        self.init()
        let btn = UIButton()
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        if imageName != nil{
            btn.setImage(UIImage(named: imageName!), forState: UIControlState.Normal)
            btn.setImage(UIImage(named: "\(imageName!)_highlighted"), forState: UIControlState.Highlighted)
        }
        if title != nil{
            btn.setTitle(title! as String, forState: UIControlState.Normal)
            btn.setTitleColor(UIColor(white: 80/255, alpha: 1), forState: UIControlState.Normal)
            btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
            btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        }
        
        btn.sizeToFit()
        customView = btn
    }
}
